package com.kmust.dream.wanderingdream.product.controller;

import com.kmust.dream.wanderingdream.comm.pojo.ResultBean;
import com.kmust.dream.wanderingdream.product.entity.ProductCategory;
import com.kmust.dream.wanderingdream.product.service.ProductCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/product/productCategory")
@Api(value = "商品分类API")
public class ProductCategoryController {
    @Autowired
    private ProductCategoryService productCategoryService;

    /**
     * 获取所有的分类
     *
     * @return resultBean
     */
    @ApiOperation(value = "获取所有的商品分类", notes = "无参数")
    @GetMapping("/getAllCategory")
    public ResultBean getAllCategory() {
        return productCategoryService.getAllCategory();
    }

    /**
     * 根据主键获取分类
     *
     * @param categoryId 分类id
     * @return resultBean
     */
    @ApiOperation(value = "根据主键获取分类", notes = "参数是主键")
    @GetMapping("/getCategoryOne/{categoryId}")
    public ResultBean getCategoryOne(@PathVariable Integer categoryId) {
        return productCategoryService.getCategoryOne(categoryId);
    }

    /**
     * 获取当前分类的子分类
     *
     * @param parentCategory 父类id
     * @return resultBean
     */
    @ApiOperation(value = "根据父类id获取当前分类的子分类", notes = "参数是父类主键id")
    @GetMapping("/getSonCategory/{parentCategory}")
    public ResultBean getSonCategory(@PathVariable Integer parentCategory) {
        return productCategoryService.getSonCategory(parentCategory);
    }

    /**
     * 获取顶级分类
     *
     * @return resultBean
     */
    @ApiOperation(value = "获取顶级分类", notes = "无参数")
    @GetMapping("/getFirstCategory")
    public ResultBean getFirstCategory() {
        return productCategoryService.getFirstCategory();
    }

    /**
     * 添加分类
     *
     * @param productCategory 商品分类
     * @return resultBean
     */
    @ApiOperation(value = "添加分类", notes = "参数为商品分类json")
    @PostMapping("/addCategory")
    public ResultBean addCategory(@RequestBody ProductCategory productCategory) {
        return productCategoryService.addCategory(productCategory);
    }

    /**
     * 更新分类
     *
     * @param productCategory 商品分类
     * @return resultBean
     */
    @ApiOperation(value = "更新分类", notes = "参数是商品分类json")
    @PutMapping("/updateCategory")
    public ResultBean updateCategory(@RequestBody ProductCategory productCategory) {
        return productCategoryService.updateCategory(productCategory);
    }

    /**
     * 假删除分类
     *
     * @param categoryId 分类id
     * @return resultBean
     */
    @ApiOperation(value = "根据主键进行假删除", notes = "参数是主键")
    @DeleteMapping("/deleteCategory/{categoryId}")
    public ResultBean deleteCategory(@PathVariable Integer categoryId) {
        return productCategoryService.deleteCategory(categoryId);
    }

    /**
     * 后台管理系统前端获取级联列表
     *
     * @return resultBean
     */
    @ApiOperation("后台管理系统前端获取级联列表")
    @GetMapping("/getAllCategoryFont")
    public ResultBean getAllCategoryFont() {
        return productCategoryService.getAllCategoryFont();
    }


}
